package com.lebang.controller.api.bus;

import com.lebang.common.Require;
import com.lebang.feign.bus.MemberBussCollectRecordFeign;
import com.lebang.model.RequestUserInfo;
import com.lebangweb.common.TextUtil;
import com.lebangweb.response.Callback;
import com.lebangweb.response.JsonData;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * 用户收藏公交线路
 * @Author: ljx
 * @Date: 2020/11/30
 */
@Api(tags ="用户收藏公交线路")
@RestController
@RequestMapping("/api/buss")
public class MemberBussCollectApi {
    @Autowired
    private MemberBussCollectRecordFeign feign;

    @Require
    @ApiOperation("添加线路收藏")
    @PostMapping("/collectrecord/add")
    public JsonData add(HttpServletRequest request,
                        @ApiParam(name = "城市id") @RequestParam("cityId") String cityId,
                        @ApiParam(name = "线路") @RequestParam("route") String route,
                        @ApiParam(name = "线路id") @RequestParam("routeId") String routeId,
                        @ApiParam(name = "终点站") @RequestParam("endStan") String endStan,
                        @ApiParam(name = "路线编号") @RequestParam("routeNum") String routeNum){
        if (TextUtil.isEmpty(cityId) || TextUtil.isEmpty(route) || TextUtil.isEmpty(routeNum) || TextUtil.isEmpty(routeId) || TextUtil.isEmpty(endStan)) {
            return Callback.fail("201", "收藏失败");
        }
        RequestUserInfo userInfo = new RequestUserInfo(request);
        return feign.addRecord(userInfo, cityId, route, routeId, endStan, routeNum);
    }

    @Require
    @ApiOperation("查询当前城市线路收藏")
    @PostMapping("/collectrecord/get")
    public JsonData get(HttpServletRequest request, @ApiParam(name = "城市id") @RequestParam("cityId") String cityId) {
        if (TextUtil.isEmpty(cityId)) {
            return Callback.success("201", "查询失败");
        }
        RequestUserInfo userInfo = new RequestUserInfo(request);
        return feign.selectByCityId(userInfo,cityId);
    }

    @Require
    @ApiOperation("取消线路收藏")
    @PostMapping("/collectrecord/update")
    public JsonData update(HttpServletRequest request,
                           @ApiParam(name = "城市id") @RequestParam("cityId") String cityId,
                           @ApiParam(name = "线路id") @RequestParam("routeId") String routeId) {
        if (TextUtil.isEmpty(cityId) || TextUtil.isEmpty(routeId)) {
            return Callback.success("201", "操作失败");
        }
        RequestUserInfo userInfo = new RequestUserInfo(request);
        return feign.updateByCityId(userInfo,cityId,routeId);
    }

    @Require
    @ApiOperation("线路置顶")
    @PostMapping("/collectrecord/top")
    public JsonData top(HttpServletRequest request,
                        @ApiParam(name = "城市id") @RequestParam("cityId") String cityId,
                        @ApiParam(name = "线路id") @RequestParam("routeId") String routeId) {
        if (TextUtil.isEmpty(cityId) || TextUtil.isEmpty(routeId)) {
            return Callback.success("201", "操作失败");
        }
        RequestUserInfo userInfo = new RequestUserInfo(request);
        return feign.top(userInfo,cityId,routeId);
    }

    @Require
    @ApiOperation("取消线路置顶")
    @PostMapping("/collectrecord/canceltop")
    public JsonData cancelTop(HttpServletRequest request,
                        @ApiParam(name = "城市id") @RequestParam("cityId") String cityId,
                        @ApiParam(name = "线路id") @RequestParam("routeId") String routeId) {
        if (TextUtil.isEmpty(cityId) || TextUtil.isEmpty(routeId)) {
            return Callback.success("201", "操作失败");
        }
        RequestUserInfo userInfo = new RequestUserInfo(request);
        return feign.cancelTop(userInfo,cityId,routeId);
    }

    @Require
    @ApiOperation("换线")
    @PostMapping("/collectrecord/changeline")
    public JsonData changeLine(HttpServletRequest request,
                               @ApiParam(name = "城市id") @RequestParam("cityId") String cityId,
                               @ApiParam(name = "线路id") @RequestParam("routeId") String routeId) {
        if (TextUtil.isEmpty(cityId) || TextUtil.isEmpty(routeId)) {
            return Callback.success("201", "操作失败");
        }
        RequestUserInfo userInfo = new RequestUserInfo(request);
        return feign.changeLine(userInfo,cityId,routeId);
    }
}
